<template>
  <div class="app-container">
    
    <!--功能菜单-->
    <div class="menu">
      <el-button type="primary" icon="el-icon-plus" @click="addBanner()">新增</el-button>
    </div>

    <!-- 表格 -->
    <el-table v-loading="listLoading" :data="list" element-loading-text="数据加载中" border fit highlight-current-row row-class-name="myClassList">

      <el-table-column label="序号" width="70" align="center">
        <template slot-scope="scope">
          {{ (page - 1) * limit + scope.$index + 1 }}
        </template>
      </el-table-column>

      <el-table-column label="轮播图缩略" width="370" align="center">
        <template slot-scope="scope">
          <div class="info">
            <div class="pic">
              <img :src="scope.row.imageUrl" :alt="scope.row.title" width="280px">
            </div>
            <div class="title">
              <el-tag>{{ scope.row.title }}</el-tag>
            </div>
          </div>

        </template>
      </el-table-column>

      <el-table-column label="图片类型（暂时全部都是pc图）" width="200" align="center" >
        <template slot-scope="scope">
          <el-tag>{{ true ? 'pc端' : '移动端'}}</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="跳转路径" align="center" >
        <template slot-scope="scope">
          {{ scope.row.linkUrl }}
        </template>
      </el-table-column>

      <el-table-column label="创建时间" align="center">
        <template slot-scope="scope">
          {{ scope.row.gmtCreate.substr(0, 10) }}
        </template>
      </el-table-column>
      <el-table-column label="发布时间" align="center">
        <template slot-scope="scope">
          {{ scope.row.gmtModified.substr(0, 10) }}
        </template>
      </el-table-column>



      <el-table-column label="操作" width="150" align="center">
        <template slot-scope="scope">

          <router-link :to="'/cms/banner/update/'+scope.row.id">
            <el-button type="text" size="mini" icon="el-icon-edit">修改</el-button>
          </router-link>
          <el-button type="text" size="mini" icon="el-icon-delete">删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination
      :current-page="page"
      :page-size="limit"
      :total="total"
      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="getBannerData"
    />
  </div>
</template>

<script>
import banner from '@/api/cms/banner'

export default {

  data() {
    return {
      listLoading: true, // 是否显示loading信息
      list: null, // 数据列表
      total: 0, // 总记录数
      page: 1, // 页码
      limit: 10, // 每页记录数
    }
  },

  created() { // 当页面加载时获取数据
    this.getBannerData()
  },

  methods: {

    getBannerData(page = 1) { 
      // 调用api层获取数据库中的数据
      
      this.page = page
      this.listLoading = true
      banner.getPageList(this.page, this.limit).then(res => {
        // debugger 设置断点调试
        console.log(res)
        if (res.success === true) {
          this.list = res.data.items
          this.total = res.data.total
        }
        this.listLoading = false
      })
    },

    addBanner(){
      this.$router.push({ path: '/cms/banner/add'})
    }

  }
}
</script>

<style scoped>
.myClassList .info {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.myClassList .info .pic {
    width: 80%;
    height: 90%;
    overflow: hidden; 
}
.myClassList .info .pic a {
    display: block;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}
.myClassList .info .pic img {
    display: block;
    width: 100%;
}
.myClassList td .info .title {
    width: 280px;
}
.myClassList td .info .title a {
    display: block;
    height: 48px;
    line-height: 24px;
    overflow: hidden;
    color: #00baf2;
    margin-bottom: 12px;
}
.myClassList td .info .title p {
    line-height: 20px;
    margin-top: 5px;
    color: #818181;
}

.menu{
  margin-bottom: 20px;
}
</style>